package contestseeker.visitors;

import org.htmlparser.Tag;
import org.htmlparser.tags.TableColumn;
import org.htmlparser.tags.TableRow;
import org.htmlparser.tags.TableTag;



public class SPOJ extends VisitorBase {
	public static final String NAME = "SPOJ";
	public static final String URL = "http://www.spoj.pl/contests/";
	public static final String ENCODING = "ISO-8859-2";
	public static final String TITLE = "SPOJ Running contests";
	private boolean running = true;
	
	public SPOJ() {
		super.URL = URL;
		super.ENCODING = ENCODING;
		super.TITLE = TITLE;
		super.NAME = NAME;
	}
	
	@Override
	public void visitTag(Tag tag)
	{
		if (tag instanceof TableTag)
		{
			TableTag table = (TableTag)tag;
			if (table.getAttribute("class") != null && table.getAttribute("class").compareTo("problems") == 0)
			{
				if (!running) {
					running = true;
					return;
				} else {
					running  = false;
				}
				TableRow row;
				TableColumn columns[];
			
				this.beginTable(TITLE);
				this.addHeader(table.getRow(0));
				for (int i = 0; i < table.getRowCount(); ++i)
				{
					row = table.getRow(i);
					columns = row.getColumns();
					if (columns.length == 4)
						this.addColumns(columns);
				}
				this.endTable();
			}
		}
	}
}
